<template>
  <div class="wrap">
    <el-card class="header-card">
      <div class="item">
        <p class="font-bold">{{$t('table.shipmentNumber')}}：{{ data.shipmentNo }}</p>
        <p class="font-bold">发货计划：
          <el-link
            :underline="false"
            type="primary"
            @click="jumpPage('shippingPlanInfo', {id: data.planId})"
          >
            {{data.shippingPlanNo}}
          </el-link>
        </p>

        <p class="font-bold" v-if="labelOrder">{{ $t('table.贴标单号') }}：
          <el-link
            :underline="false"
            type="primary"
            @click="jumpLabelOrderInfo(labelOrder.id,true)"
          >
            {{labelOrder.labelNo}}
          </el-link>
        </p>

        <p class="font-bold" v-if="data.combinationOrder">{{ $t('table.组装单号') }}：
          <el-link
            :underline="false"
            type="primary"
            @click="jumpCombinationInfo(combinationOrder.id, true)"
          >
            {{combinationOrder.combinationNo}}
          </el-link>
        </p>
        <p>
          货件类型：{{getShipmentTypeStr2(data.shipmentType)}}
        </p>
        <template v-if="data.planType === PLAN_TYPE_FL()">
          <p>
            报关方式：{{getShipmentBGMethodStr(data.BGMethod)}}
          </p>
        </template>

        <template v-if="isShipmentFullType">
          <p>
            <span class="mgr20">官方仓库：{{data.officialWarehouseName}}</span>
            <span class="mgr20">店铺ID：{{data.accountId}}</span>
            <span class="mgr20">货件ID：{{data.fullShipmentId}}</span>
          </p>
        </template>


        <p>
          <span style="margin-right: 20px">{{ $t('table.Expected number of SKU types to be received') }}：{{data.exSkuNum}}</span>
          <span class="mgr20">预计入库箱子总数：{{data.exBoxNum}}</span>
          <span>{{ $t('table.Expected quantity of goods to be received') }}：{{data.exGoodsNum}}</span>
        </p>
        <p v-if="data.status2 === FINISHED_SHELVES()">
         <span class="mgr20">实际入库SKU种数：
            <strong
              :class="{
              'true-number': data.rlSkuNum !== data.exSkuNum
              }"
            >
              {{data.rlSkuNum}}
            </strong>
          </span>
          <span class="mgr20">
            实际入库箱子总数：
            <strong
              :class="{
              'true-number': data.exBoxNum !== data.rlBoxNum
              }"
            >
              {{data.rlBoxNum}}
            </strong>
          </span>
          <span>实际入库商品总数量：
            <strong
              :class="{
              'true-number': data.rlGoodsNum !== data.exGoodsNum
              }"
            >
              {{data.rlGoodsNum}}
            </strong>
          </span>
        </p>
        <p v-if="data.status === 1">
          <span class="mgr20">{{$t('table.Warehouse administrator')}}：{{ data.adminAccount }}</span>
        </p>
        <p v-if="data.child_id!=''&&data.child_id!=0&&data.child_id!=null">
          <span >操作员：{{ data.child_name }}</span>
        </p>
        <p v-else>
          <span >操作员：{{ data.userAccount }}</span>
        </p>
      </div>
      <div class="button">
        <div v-if="labelOrder" class="mgb10">
          <el-button type="primary" @click="jumpLabelOrderInfo(labelOrder.id,true)">{{ $t('labelOrder.贴标工单') }}</el-button>
        </div>
        <div v-if="combinationOrder" class="mgb10">
          <el-button type="primary" @click="jumpCombinationInfo(combinationOrder.id, true)">{{$t('combination.组装工单')}}</el-button>
        </div>

      </div>

    </el-card>
    <div class="mgt20" v-if="data.planType === PLAN_TYPE_FL()">
      <el-radio-group v-model="currentContainerId">
        <el-radio-button
          v-for="item in containerList"
          :key="item.label"
          :label="item.label"
        >
          {{item.text}}
        </el-radio-button>
      </el-radio-group>
    </div>

    <div>
      <h4>货件进度</h4>
      <template v-if="data.planType === PLAN_TYPE_FL()">
        <shipment-steps :data="data" :history="data.history ? data.history : []"></shipment-steps>
      </template>
      <template v-else-if="data.planType === PLAN_TYPE_MW()">
        <shipment-steps2 :data="data" :history="data.history ? data.history : []"></shipment-steps2>
      </template>
    </div>

    <div>
      <h4>{{$t('shipment.shipmentDetail')}}</h4>
      <div class="table">
        <shipment-box-table :get-data="getData" :table-data="boxLabelList" :shipment="data"></shipment-box-table>
      </div>
    </div>

    <div>
      <h4>{{$t('shipment.productDetails')}}</h4>
      <div class="table">
        <shipment-goods-table :shipment-goods="shipmentGoods" :shipment="data"></shipment-goods-table>
      </div>

    </div>


    <div v-if="data.planType === PLAN_TYPE_FL() && canEdit">
      <div class="mgt20">
        <span style="font-weight: bold">报关方式：</span>
        <el-radio-group v-model="editForm.BGMethod">
          <el-radio v-for="item in allBGMethodList" :key="item" :label="item">{{getShipmentBGMethodStr(item)}}</el-radio>
        </el-radio-group>
      </div>
    </div>

    <div v-if="data.shipmentType === 'offline_delivery'">
      <div class="mgt20">
        <span style="font-weight: bold">
          配送地址：
          <choose-address :choose-id="data.userAddress.id" v-if="canEdit && data.userAddress" style="display: inline-block" @submitAddress="chooseAddress"></choose-address>
        </span>
        <div v-if="data.userAddress">
          <address-box :address="data.userAddress"></address-box>
        </div>
      </div>
    </div>

    <div v-if="isShipmentFullType" class="full-shipment-box mgt20">
      <div class="full-shipment-id mgb20" v-if="canEdit">
        <div class="title">
          货件ID <el-input placeholder="请填写本次送仓的货件ID" v-model="editForm.fullShipmentId" style="width: 300px" class="mgl10"></el-input>
        </div>

      </div>

      <div class="mgb20">
        <div class="title">上传箱标</div>
        <div class="sub-title">请上传本次送仓箱子的对应的美客多箱标，以供仓库下载应对特殊情况使用</div>
        <upload-file
          action="/shipmentV2/uploadFile"
          :file="editForm.boxPDF"
          upload-file-text="上传箱标"
          edit-file-text="修改箱标"
          @uploadFileSuccess="uploadBoxPDFSuccess"
          :can-upload="canEdit"
        ></upload-file>
      </div>

      <div class="mgb20">
        <div class="title">预约信</div>
        <div class="sub-title">本土店铺如由卖家预约送仓，请上传预约信。跨境店铺请忽略</div>
        <template v-if="canEdit">
          <upload-file
            action="/shipmentV2/uploadFile"
            :file="editForm.appointmentPDF"
            upload-file-text="上传预约信"
            edit-file-text="修改预约信"
            @uploadFileSuccess="uploadAppointmentPDFSuccess"
            :can-upload="canEdit"
          ></upload-file>
        </template>
        <template v-else>
          未上传预约信
        </template>

      </div>
    </div>



    <div class="remark remark-box">
      <h4>{{$t('shipment.step4Text10')}}：</h4>
      <el-input
        type="textarea"
        :placeholder="$t('shipment.step4Text11')"
        v-model="data.remark"
        :autosize="{minRows: 4}"
      ></el-input>
      <el-button type="primary" @click="editRemark" class="remark-btn" v-if="!isFinishedShipmentStatus">修改</el-button>
    </div>

    <div v-if="data.imageArr && data.imageArr.length > 0">
      <h4>货件图片：</h4>
      <div style="color: #7F7F7F; font-size: 14px; margin-top: -10px;">
        <div>
          <span>系统会为您保存180天，180天后系统将自动清除这些图片</span>
        </div>
      </div>
      <div>
        <div v-for="(item, index) in data.imageArr" :key="index" style="margin-right: 10px; margin-left: 10px; display: inline-block; margin-top: 30px; margin-bottom: 30px;">
          <el-image
            class="zoomable-image"
            style="width: auto; height: 200px; vertical-align: top;"
            :src="item"
            :preview-src-list="data.imageArr"
          ></el-image>
        </div>
      </div>
    </div>

    <div class="footer" style="margin-top: 30px">
      <el-button @click="goBack">{{$t('common.back')}}</el-button>
      <template v-if="canEdit">
        <el-button type="primary" @click="editShipment" :loading="buttonLoading">{{$t('common.confirmModification')}}</el-button>
      </template>
      <template v-if="data.status === -1 && false">
        <el-button type="primary" :loading="buttonLoading" @click="editShipment(-1)">{{$t('common.save')}}</el-button>

        <el-button type="primary" :loading="buttonLoading" @click="editShipment(0)" v-if="false">{{$t('common.confirm')}}</el-button>

        <el-button type="primary" :loading="buttonLoading" @click="editShipment(1)">{{$t('common.confirm')}}</el-button>

        <el-button type="info" @click="delShipment" :loading="buttonLoading">{{$t('shipment.cancelShipment')}}</el-button>
      </template>
      <template v-if="data.status === 0 && false">

        <template v-if="data.type === 2">
          <export-box :id="data.id"></export-box>
        </template>
        <el-button type="info" @click="delShipment" :loading="buttonLoading" v-if="!data.labelOrder || data.labelOrder.status !== 2">{{$t('shipment.cancelShipment')}}</el-button>
      </template>

      <template v-if="data.status === 1 && data.type === 1 && data.cancel === 0">
        <el-button @click="cancelShipment()" type="danger">{{ $t('shipment.作废') }}</el-button>
      </template>
    </div>
  </div>

</template>

<script>
import {
  cancelShipment,
  deleteShipment,
  editShipment, getAddShipmentData,
  getShipmentGoodsPage,
  getShipmentInfo,
  printShipmentBoxPDF
} from "@/api/shipment";
import {deepCopy, getFalabellaName, getPlatformShortNameByAccountNum, getPlatformTextColor} from "@/utils";
import {jumpCombinationInfo, jumpLabelOrderInfo, jumpPage, jumpPageNewTag} from "@/utils/jumpView";
import ExportBox from "@/views/shipment/components/ExportBox.vue";
import {
  ABOLISHED,
  FINISHED_SHELVES, getShipmentBGMethodStr,
  getShipmentStatusStr,
  getShipmentTypeStr,
  getShipmentTypeStr2, OFFICIAL_DELIVERED, OFFLINE_DELIVERED, WAIT_CONFIRM, WAIT_FL_RECEIVE,
  WAIT_MAKE_CABINET
} from "@/utils/shipment";
import {getLabelStatusStr} from "@/utils/labelOrder";
import MLCodeColumn from "@/views/stock/components/MLCodeColumn.vue";
import GoodsSize from "@/views/stock/components/GoodsSize";
import Log from "echarts/src/scale/Log";
import {getCombinationStatus} from "../../utils/combination";
import ShipmentBoxTable from "@/views/shipment/components/ShipmentBoxTable.vue";
import ShipmentGoodsTable from "@/views/shipment/components/ShipmentGoodsTable.vue";
import {STATUS_RECEIVED, STATUS_SORTED} from "@/utils/boxLabel";
import {getContainerStatusStr} from "@/utils/container";
import {PLAN_TYPE_FL, PLAN_TYPE_MW} from "@/utils/shippingPlan";
import ShipmentSteps from "@/views/shipment/components/ShipmentSteps.vue";
import ShipmentSteps2 from "@/views/shipment/components/ShipmentSteps2.vue";
import UploadFile from "@/views/shipment/components/UploadFile.vue";
import request from "@/utils/request";
import ChooseAddress from "@/views/userAddress/components/ChooseAddress.vue";
import AddressBox from "@/views/shipment/components/AddressBox.vue";
import {editRemark} from "@/api/shipmentV2";

export default {
  name: "shipmentInfo",
  components: {
    AddressBox,
    ChooseAddress, UploadFile, ShipmentSteps2, ShipmentSteps, ShipmentGoodsTable, ShipmentBoxTable, ExportBox},
  data(){
    return {
      data: {
        accountList: [],
        userId: '',
        userAccount: '',
        adminAccount: '',
        adminId: '',
        confirmTime: '',
        createTime: '',
        exBoxNum: '',
        exGoodsNum: '',
        exSkuNum: 0,
        remark: '',
        rlBoxNum: '',
        rlGoodsNum: '',
        rlSkuNum: 0,
        shipmentNo: '',
        estimateTime: '',
        type: 0,
      },
      shipmentBox: [],
      shipmentGoods: [],
      shipmentGoodsApi: [],
      // boxLabelList: [],
      shipmentBoxLabelList: [],
      shipmentGoodsParams: {
        shipmentId: 0,
        page: 1,
        pageSize: 100,
      },
      labelOrder: null,
      combinationOrder: null,
      id: '',
      loading: false,
      buttonLoading: false,
      originData: {
        box: [],
        goods: [],
        remark: '',
        estimateTime: '',
      },
      currentContainerId: '',
      editForm: {
        id: '',
        BGMethod: '',
        appointmentPDF: '',
        boxPDF: '',
        fullShipmentId: '',
        remark: '',
        address: {

        },
      },
      allBGMethodList: [],
    }
  },
  watch: {
    containerList(){
      if(this.data.planType === PLAN_TYPE_FL){
        this.currentContainerId = this.containerList[0].label
      }
    },
    currentContainerId(){
      this.$emit('update:containerId', this.currentContainerId)
    },
  },
  computed:{
    accountName(){
      const accountName = [];
      this.data.accountList.forEach(item=>{
        accountName.push(item.showName)
      })
      return accountName.join('、')
    },
    // 是否能编辑数据
    canEdit(){
      const arr = [WAIT_CONFIRM, WAIT_FL_RECEIVE];
      if(arr.includes(this.data.status2)){
        return true
      }
      return false
    },
    showShipmentGoodsData(){
      const startIndex = (this.shipmentGoodsParams.page - 1) * this.shipmentGoodsParams.pageSize; // 起始索引位置
      return this.shipmentGoods.slice(startIndex, startIndex + this.shipmentGoodsParams.pageSize); // 返回切片后的结果
    },
    // 预计的总货值
    sumGoodsValue(){
      if(this.data.status === 1){
        return this.data.rlSumGoodsValue
      }else{
        return this.shipmentGoods.reduce((prev,item) => {
          return prev + item.goodsValue * item.exGoodsNum
        },0);
      }
    },
    containerList(){
      const arr = [];
      if(this.waitCabinetBoxList.length > 0){
        arr.push({label: WAIT_MAKE_CABINET, text: '国内待装柜'})
      }
      if(this.receivedBoxList.length > 0){
        arr.push({label: STATUS_RECEIVED, text: '国内未接收'})
      }
      if(this.data.containerList){
        this.data.containerList.forEach(item=>{
          const obj = {
            label: item.id,
            text: '货柜-' + (item.containerName) + `(${getContainerStatusStr(item.status)})`
          }
          arr.unshift(obj)
        })
      }
      return arr;
    },
    boxLabelList(){
      let arr = this.shipmentBoxLabelList
      if(typeof this.currentContainerId === 'number'){
        return  arr.filter(item=> item.containerId === this.currentContainerId)
      }else if(typeof this.currentContainerId === 'string'){
        switch (this.currentContainerId){
          case STATUS_RECEIVED:
            return this.receivedBoxList
          case WAIT_MAKE_CABINET:
            return this.waitCabinetBoxList
        }
      }
      return arr;
    },
    receivedBoxList(){
      return this.shipmentBoxLabelList.filter(item=> item.isReceived === 0)
    },
    waitCabinetBoxList(){
      return this.shipmentBoxLabelList.filter(item=> !item.containerId && item.isReceived === 1)
    },
    // 是否官方仓类型
    isShipmentFullType(){
      return this.data.shipmentType === 'mkd_full' || this.data.shipmentType === 'mkd_cbt_full'
    },
    // 是不是最后的完成状态
    isFinishedShipmentStatus(){
      const arr = [OFFLINE_DELIVERED, FINISHED_SHELVES, OFFICIAL_DELIVERED, ABOLISHED]
      return arr.includes(this.data.status2)
    },
  },
  created() {
    this.id = this.$route.query.id;
    this.getBaseData()
    this.getData()
  },
  methods:{
    getShipmentBGMethodStr,
    FINISHED_SHELVES() {
      return FINISHED_SHELVES
    },
    jumpPage,
    jumpPageNewTag,
    PLAN_TYPE_MW() {
      return PLAN_TYPE_MW
    },
    PLAN_TYPE_FL() {
      return PLAN_TYPE_FL
    },
    getShipmentTypeStr2,
    getCombinationStatus,
    jumpCombinationInfo,
    getShipmentStatusStr,
    getLabelStatusStr,
    getShipmentTypeStr,
    jumpLabelOrderInfo,
    getPlatformTextColor,
    getPlatformShortNameByAccountNum,
    getFalabellaName,
    getData(){
      this.loading = true
      getShipmentInfo(this.id)
        .then(res=>{
          this.loading = false;
          this.data = deepCopy(res.data)

          this.shipmentBox = [];
          this.shipmentBoxLabelList = res.data.boxLabelList;
          res.data.shipmentBox.forEach(item=>{
            item.editNum = item.exBoxNum
            this.shipmentBox.push(item)
          })

          this.shipmentGoods = [];
          // 计算一共有多少页 请求数据
          this.shipmentGoodsApi = [];
          let totalPage = Math.ceil(res.info.shipmentGoodsTotal / this.shipmentGoodsParams.pageSize)
          for (let page = 1; page <= totalPage ; page++) {
            const params = {
              page: page,
              pageSize: this.shipmentGoodsParams.pageSize,
              shipmentId: this.data.id,
            }
            this.shipmentGoodsApi.push(false)
            this.getShipmentGoods(params)
          }


          // labelOrder
          this.labelOrder = deepCopy(res.data.labelOrder)
          this.combinationOrder = deepCopy(res.data.combinationOrder)

          this.editForm.id = this.data.id
          this.editForm.BGMethod = this.data.BGMethod
          this.editForm.appointmentPDF = this.data.appointmentPDF
          this.editForm.boxPDF = this.data.boxPDF
          this.editForm.fullShipmentId = this.data.fullShipmentId
          this.editForm.remark = this.data.remark
          this.editForm.address = this.data.userAddress


          this.$store.dispatch('user/getInfo');
        })
    },
    getBaseData(){
      getAddShipmentData()
        .then(res=>{
          this.allBGMethodList = deepCopy(res.data.BGMethodList)
        })
    },
    getShipmentGoods(params){
      this.loading = true
      getShipmentGoodsPage(params)
        .then(res=>{
          res.data.forEach(item=>{
            item.editNum = item.exGoodsNum
            item.editGoodsNumBoxStatus = 0 // 编辑箱装数
            item.editGoodsNumInBox = item.goodsNumInBox
            item.beforeGoodsNumInBox = item.goodsNumInBox
            item.beforeExGoodsMixinNum = item.exGoodsMixinNum // 混件数量
            item.beforeExGoodsBoxNum = item.exGoodsBoxNum
            item.beforeIsCombination = item.isCombination

            // 货值
            item.editGoodsValueStatus = 0 // 编辑货值状态
            item.editGoodsValue = item.goodsValue; // 当前货值

            this.shipmentGoods.push(item)
          })
          this.shipmentGoodsApi[params.page - 1] = true
          if(this.shipmentGoodsApi.every(item => item)){
            this.loading = false
            this.originData.remark = this.data.remark;
            this.originData.box = deepCopy(this.shipmentBox)
            this.originData.goods = deepCopy(this.shipmentGoods)
            this.originData.estimateTime = deepCopy(this.data.estimateTime)
          }
        })
    },
    // 修改 status -1 保存 0 待确认 1待确认并打印箱标
    editShipment(){
      if(this.isShipmentFullType){
        if(!this.editForm.fullShipmentId){
          this.$errorMessage('请填写货件ID')
          return;
        }
        if(!this.editForm.boxPDF){
          this.$errorMessage('请上传箱标')
          return;
        }
      }
      this.buttonLoading = true
      request({
        url: '/shipmentV2/editShipment',
        method: 'put',
        data: this.editForm,
        handleError: true,
      })
        .then(res=>{
          this.buttonLoading = false
          if(res.error === 0){
            this.getData()
            this.$successMessage(res.message)
          }else{
            this.$errorMessage(res.message)
          }
        })
    },
    editShipmentV2(postData,print = false,labelView = false){
      this.buttonLoading = true
      editShipment(postData)
        .then(res=>{
          this.buttonLoading = false
          if(res.error === 0){
            this.$successMessage(res.message)
            this.getData()
            if(print && this.data.type === 2){
              this.printBox()
            }
            if(labelView && res.info.labelOrderId){
              this.jumpLabelOrderInfo(res.info.labelOrderId,true)
            }
          }else{
            this.$errorMessage(res.message)
          }
        })
    },
    printBox(){
      printShipmentBoxPDF(this.id)
        .then(res=>{
          const pdfFile = window.URL.createObjectURL(
            new Blob([res.data], { type: "application/pdf" })
          );

          // 跳转页面预览
          window.open(pdfFile);
          // 60秒后释放
          setTimeout(()=>{
            URL.revokeObjectURL(pdfFile); //释放URL对象
          },60000)
        })
    },
    // 撤销货件
    delShipment(){
      this.$warning( this.$t('shipment.cancelShipmentText'),{
        title: this.$t('shipment.cancelShipment'),
      })
        .then(()=>{
          this.buttonLoading = true
          deleteShipment(this.id)
            .then(res=>{
              if(res.error === 0){
                this.$successMessage(res.message)
                this.goBack()
              }else{
                this.$errorMessage(res.message)
              }
            })
        })
        .catch(()=>{

        })
    },
    // 返回上一页
    goBack(){
      this.$router.go(-1);
    },
    // 判断是否有修改
    disableEdit(){
      return JSON.stringify(this.originData.box) === JSON.stringify(this.shipmentBox) &&
        JSON.stringify(this.originData.goods) === JSON.stringify(this.shipmentGoods) &&
        this.data.remark === this.originData.remark &&
        this.data.estimateTime === this.originData.estimateTime
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      const mergeCell = this.getMergeCell(this.showShipmentGoodsData)
      if(mergeCell[column.property]){
        if(mergeCell[column.property][rowIndex]) {
          return [mergeCell[column.property][rowIndex], 1]
        } else {
          // 如果为0则为需要合并的行
          return [0, 0];
        }
      }
    },
    getMergeCell(list){
      const mergeObj = {};
      // 根据suitId合并的字段
      const mergeFieldArr = [
        'image',
        'title',
        'goodsNumInBox',
        'exTotalGoodsNum',
        'exGoodsNum',
        'rlGoodsNum',
        'goodsValue',
        'isCombination',
        'weight',
      ];

      mergeFieldArr.forEach(key=>{
        mergeObj[key] = [1];
      })

      let mergeFieldKey = 0;
      list.forEach((item,index)=>{
        // 第一列数据不处理
        if(index === 0){
          return;
        }
        // 根据suitId 合并


        if(item.suitId && item.suitId === list[index - 1].suitId){
          mergeFieldArr.forEach(key=>{
            mergeObj[key][mergeFieldKey] += 1;
            mergeObj[key].push(0); // 添加一个0 站位
          })
        }else{
          mergeFieldKey = index; // 记录当前行
          mergeFieldArr.forEach(key=>{
            mergeObj[key].push(1); // 添加一个1
          })
        }
      })

      return mergeObj;
    },
    // 编辑箱装数
    editGoodsNumBox(row){
      row.editGoodsNumBoxStatus = 1
      this.$nextTick(()=>{
        this.$refs.goodsNumBoxInput.focus()
      })
    },
    // 计算预计入库商品总数
    getExGoodsNum(row){
      const suitId = row.suitId
      let num = 0
      this.shipmentGoods.filter(item=> item.suitId === suitId)
        .forEach(item=>{
          const num1 = item.goodsNumInBox * item.exGoodsBoxNum // 箱装数数量
          const num2 = item.exGoodsMixinNum
          item.exGoodsNum = num1 + num2
          if(num1){
            num += num1
          }
          if(num2){
            num += num2
          }
        })
      return num
    },
    getRlGoodsNum(row){
      const suitId = row.suitId
      let num = 0
      this.shipmentGoods.filter(item=> item.suitId === suitId)
        .forEach(item=>{
          num += row.rlGoodsNum
        })
      return num
    },
    // 改变预计入库箱子数
    changeExGoodsBoxBox(){
      let sumBoxNum = 0
      this.shipmentGoods.forEach(item=> {
        if(!item.exGoodsBoxNum){
          item.exGoodsBoxNum = 0
        }
        sumBoxNum += item.exGoodsBoxNum
      })
      this.shipmentBox.some(item=>{
        if(item.boxType === 4){
          //item.exBoxNum = sumBoxNum
          item.editNum = sumBoxNum
          return true;
        }
      })
    },
    // 作废
    cancelShipment(){
      this.$warning(this.$t('shipment.确定要作废当前待送仓货件单吗，作废后请主动联系仓库寄回或创建新的货件单重新入库'),{
        title: this.$t('shipment.作废当前货件？'),
      })
        .then(()=>{
          this.delLoading = true
          cancelShipment(this.data.id)
            .then(res=>{
              if(res.error === 0){
                this.$successMessage(res.message)
                this.getData()
              }else{
                this.$errorMessage(res.message)
              }
            })
        })
        .catch(()=>{

        })
    },
    // 修改箱装数
    changeGoodsBoxNum(row){
      const suitId = row.suitId
      this.shipmentGoods.filter(item => item.suitId === suitId)
        .forEach(item=>{
          item.editGoodsNumInBox = row.editGoodsNumInBox
          item.goodsNumInBox = item.editGoodsNumInBox
        })
    },
    getGoodsSizeList(row){
      return this.showShipmentGoodsData.filter(item => item.suitId === row.suitId)
    },
    // 编辑货值
    editGoodsValue(row){
      row.editGoodsValueStatus = 1
      row.editGoodsValue = row.goodsValue
      this.$nextTick(()=>{
        this.$refs.goodsValueInput.focus()
      })
    },
    // 修改货值
    changeGoodsValue(row){
      row.editGoodsValueStatus = 0;
      let goodsValue = parseFloat(row.editGoodsValue);
      if(isNaN(goodsValue)){
        return
      }
      if(goodsValue <= 0){
        return;
      }
      // 一个修改了货值 其他都适配的商品也要修改
      row.goodsValue = Math.round(goodsValue * 100) / 100
      this.shipmentGoods.forEach(item=>{
        if(item.suitId === row.suitId){
          item.goodsValue = row.goodsValue
        }
      })
    },
    // 更新货值
    updateGoodsValue(row){
      const suitId = row.id
      this.shipmentGoods.forEach(item=>{
        if(item.suitId === suitId){
          item.goodsValue = row.goodsValue
        }
      })
    },
    // 改变了组装
    changeIsCombination(row){
      this.shipmentGoods.filter(item => item.suitId === row.suitId)
        .forEach(item=>{
          item.isCombination = row.isCombination
        })
    },
    // 上传箱标
    uploadBoxPDFSuccess(file){
      this.editForm.boxPDF = file
    },
    // 上传送仓单
    uploadAppointmentPDFSuccess(file){
      this.editForm.appointmentPDF = file
    },
    chooseAddress(row){
      this.data.userAddress = deepCopy(row)
      this.editForm.address = deepCopy(row)
    },
    editRemark(){
      editRemark({
        id: this.data.id,
        remark: this.data.remark
      })
        .then(res=>{
          this.$sMsg(res.message)
        })
    }
  }
}
</script>

<style scoped lang="scss">
.wrap {
  padding: 30px 30px;
  .header{
    //display: flex;
    //justify-content: space-between;
  }
  .content{
    padding: 20px 0 0;
  }
  .header-card{
    font-size: 14px;
    background-color: rgba(242, 242, 242, 1);
    p{
      margin: 10px 0;
      padding: 0;
    }
    .font-bold{
      font-weight: bold;
    }
    .true-number{
      color: #FF0000;
      font-weight: 600;
    }
  }
}
.goods-table{

  .goods-title{
    font-size: 14px;
  }
  .goods-attr{
    font-size: 13px;
    color: #7F7F7F;
  }
}
.table-tips{

}
.full-shipment-box{
  .title{
    font-weight: bold;
    font-size: 16px;
    margin-bottom: 5px;
  }
  .sub-title{
    font-size: 14px;
    color: #7f7f7f;
    margin-bottom: 5px;
  }
}

.header-card{
  position: relative;
  .button{
    position: absolute;
    display: flex;
    flex-direction: column;
    right: 20px;
    top: 30px;
  }
}
.remark-box{
  position: relative;
  width: 1000px;
  .remark-btn{
    position: absolute;
    right: 8px;
    bottom: 10px;
  }
}
</style>
